﻿//========================================================= 
/**@file ComMemoryCard_TestContainer.h
 * @brief 
 * 
 * @date 2016-08-13   12:00:02
 * @author Zhyioo 
 * @version 1.0
 */ 
//--------------------------------------------------------- 
#ifndef _LIBZHOUYB_COMMEMORYCARD_TESTCONTAINER_H_
#define _LIBZHOUYB_COMMEMORYCARD_TESTCONTAINER_H_
//--------------------------------------------------------- 
#include "ComICC_TestContainer.h"
//--------------------------------------------------------- 
namespace zhou_yb {
namespace application {
namespace test {
//--------------------------------------------------------- 
/**
 * @brief 接触式存储卡接口适配器
 * @date 20160813 14:42
 *
 * @param TContainer 需要适配的底层容器
 * @param TInterface 转换后的接口类型
 * @param TMemoryCardAdapter 存储卡适配器类型
 * @param CardType 需要识别的存储卡类型枚举值
 */
template<class TContainer, class TInterface, class TMemoryCardAdapter, ComContactStorageCardDevAdapter::CardType CardType>
class ComMemoryCard_TestContainer : public ITestContainer<typename TContainer::DeviceType, IMemoryCard>
{
protected:
    TContainer _testContainer;
    TMemoryCardAdapter _memoryCard;
public:
    virtual Ref<TInterface> Adapter(const Ref<typename TContainer::DeviceType>& dev, TInterface*, TextPrinter& printer)
    {
        // 识别卡并比较卡片类型 
        ComContactStorageCardDevAdapter::CardType cardType = ComContactStorageCardDevAdapter::Card_Auto;
        typename TContainer::TransInterfaceType* pInterface = NULL;
        Ref<typename TContainer::TransInterfaceType> ref = _testContainer.Adapter(dev, pInterface, printer);
        _memoryCard.SelectDevice(ref);
        if(_memoryCard.DistinguishCardType(0x00, &cardType) && cardType == CardType)
            return _memoryCard;
        return Ref<IMemoryCard>();
    }
};
//--------------------------------------------------------- 
} // namespace test 
} // namespace application 
} // namespace zhou_yb 
//--------------------------------------------------------- 
#endif // _LIBZHOUYB_COMMEMORYCARD_TESTCONTAINER_H_
//========================================================= 